package com.xgst.lib.utils

import android.app.Activity

/**
 * Activity生命周期管理
 */
object ActivityLifecycleManager {

    private val map = mutableMapOf<Class<*>,Activity>()

    fun put(activity:Activity){
        map.put(activity.javaClass,activity)
    }

    fun remove(activity:Activity){
        map.remove(activity.javaClass)
    }

    fun finish(activity:Class<*>){
        map.get(activity)?.finish()
    }

    fun finishAll(){
        map.forEach { it.value.finish() }
    }

    /**
     * 跳转到欢迎页
     */
    fun finishAllToSplash(){
        map.forEach {
            if(!it.value.localClassName.contains("SplashActivity")){
                it.value.finish()
            }
        }
    }
}